<?php
//由ThinkphpHelper自动生成,请根据需要修改
namespace Api\Controller;
use Think\Controller;

class WycCompanyController extends Controller {
public function all(){
	$wyc_companyModel = M('WycCompany');
	$count = $wyc_companyModel->where()->count();
	$Page = new \Think\Page($count,15);	//实例化分页类 传入总记录数和每页显示的记录数(15)
	$show = $Page->show();	//分页显示输出
	$wyc_companyList = $wyc_companyModel->where()->limit($Page->firstRow.','.$Page->listRows)->select();	//分页查询
	$this->assign('page',$show);	//赋值分页输出
	$this->assign('wyc_companyList', $wyc_companyList);
	$this->display();
}

public function add(){
	if(IS_POST){
		$wyc_companyModel = M('WycCompany');
		$wyc_companyModel ->create();
		$flag = $wyc_companyModel ->add();
		if($flag){
			$this->success('新建成功',U('WycCompany/all')); 
		}else{
			$this->error('新建失败',U('WycCompany/all')); 
		}
	}else{
		$this->display(); 
	}
}

public function edit(){
	$wyc_companyModel = M('WycCompany');
	if(IS_POST){
		$wyc_companyModel ->create();
		$flag = $wyc_companyModel ->save();
		if($flag){
			$this->success('编辑成功',U('WycCompany/all')); 
		}else{
			$this->error('编辑失败',U('WycCompany/all')); 
		}
	}else{
		$id = I('id'); 
		$wyc_company = $wyc_companyModel->find($id);
		$this->assign('wyc_company', $wyc_company);
		$this->display();
	}
}

public function delete(){
	$wyc_companyModel = M('wyc_company');
	$id = I('id'); 
	$flag = $wyc_companyModel->where('id='.$id)->delete();
	if($flag){
		$this->success('删除成功', U('WycCompany/all'));
	}else{
		$this->error('删除失败', U('WycCompany/all'));
	}
}

}